$(function () {
    var code = getParam("code");
    var openid = getCookie("openid");
    var token = getCookie("token");
    if (openid != null && openid != '' && token != null && token != '') {
        //window.location.href = htmlPath + "/wallet.html";
    } else {
        if (code == null) {
            getRedirectUrl();
        } else {
            getOpenid(code);
        }
    }
})

/**
 * 获取重定向链接并跳转
 */
function getRedirectUrl() {
    $.ajax({
        url: requestPath + "/wx/getRedirectUrl",
        type: "get",
        success: function (r) {
            window.location.href = r;
        }
    });
}

/**
 * 获取openid
 * @param code
 */
function getOpenid(code) {
    var openid = '';
    $.ajax({
        url: requestPath + "/wx/getOpenid?code=" + code,
        type: "get",
        async : true,
        success: function (r) {
            if (r.code == 200) {
                openid = r.openid;
                setCookie("openid", openid,365)
            }
        }
    });
    return openid;
}